﻿package DynamicProgramming;

/**
 * @ClassName LC70
 * @Description 爬楼梯
 * @Author ZJX
 * @Date 2024/11/1 18:29
 * @Version 1.0
 */
public class LC70 {
    public int climbStairs(int n) {
        //  初始化出口 写最前面
        if (n == 1) return 1;
        if (n == 2) return 2;

        int[] dp = new int[n + 1];
        dp[1] = 1;
        dp[2] = 2;

        for (int i = 3; i <= n; i++) {
            dp[i] = dp[i - 1] + dp[i - 2];
        }
        return dp[n];
    }

    public int waysToStep(int n) {
        if (n == 1) return 1;
        if (n == 2) return 2;
        if (n == 3) return 4;

        int MOD = (int)1e9 + 7;
        int[] dp = new int[n + 1];
        dp[1] = 1;
        dp[2] = 2;
        dp[3] = 4;

        for (int i = 4; i <= n; i++) {
            dp[i] = ((dp[i - 1] + dp[i - 2]) % MOD + dp[i - 3]) % MOD;
        }
        return dp[n];
    }

}
